package com.deer.wms.kuaidiniao.web;

import com.deer.wms.kuaidiniao.constant.KdGoldAPIDemo;
import com.deer.wms.kuaidiniao.constant.WebSocketServer;
import com.deer.wms.kuaidiniao.model.EOrderRequestData;
import com.deer.wms.kuaidiniao.model.Trace;
import com.deer.wms.kuaidiniao.model.WlgzRequestData;
import com.deer.wms.kuaidiniao.service.KuaidiniaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/02/06.
*/
@RestController
@RequestMapping("/kuaidiniaos")
public class KuaidiniaoController {

    @Autowired
    private KuaidiniaoService kuaidiniaoService;

    @PostMapping("/aaa")
    public Result aaa() throws Exception {
        String fsf =  KdGoldAPIDemo.orderOnlineByJson();
      /* ResultKuaidiniao aaa= JSONObject.parseObject(fsf,ResultKuaidiniao.class);
        WebSocketServer.sandMassage(aaa.getPrintTemplate());*/
        WebSocketServer.sandMassage(KdGoldAPIDemo.getTemplate(fsf));
        return ResultGenerator.genSuccessResult();
    }


    /**
     * 电子面单
     * @param requestData
     * @return
     */
    @PostMapping("/dzmd")
    public Result dzmd(@RequestBody EOrderRequestData requestData) {
        String str = kuaidiniaoService.dzmd(requestData);
        return ResultGenerator.genSuccessResult(str);
    }

    /**
     * 即时查询
     * @param expCode
     * @param expNo
     * @return
     */
    @GetMapping("/jscx")
    public Result jscx(String expCode, String expNo) {
        List<Trace> traces = kuaidiniaoService.jscx(expCode, expNo);
        return ResultGenerator.genSuccessResult(traces);
    }

    /**
     * 物流跟踪
     * @param requestData
     * @return
     */
    @PostMapping("/wlgz")
    public Result wlgz(@RequestBody WlgzRequestData requestData) {
        String str = kuaidiniaoService.wlgz(requestData);
        return ResultGenerator.genSuccessResult(str);
    }

    /**
     * 在途监控
     * @param expCode
     * @param expNo
     * @return
     */
    @GetMapping("/ztjk")
    public Result ztjk(String expCode, String expNo) {
//        String str = kuaidiniaoService.jscx(expCode, expNo);
        return ResultGenerator.genSuccessResult();
    }

    /**
     *
     * @param expCode
     * @param expNo
     * @param isPreview
     * @return
     */
    @GetMapping("/cloudPrint")
    public Result cloudPrint(String expCode, String expNo, Integer isPreview) {
        String str = kuaidiniaoService.cloudPrint(expCode, expNo, isPreview);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 获取云打印参数
     * @param ip
     * @param expCode
     * @param expNo
     * @param printerName
     * @param isPreview
     * @return
     */
    @GetMapping("/getCloudPrintParams")
    public Result getCloudPrintParams(String ip, String expCode, String expNo, String printerName, Integer isPreview) {
//        String str = kuaidiniaoService.getCloudPrintParams(ip, expCode, expNo, printerName, isPreview);
        return ResultGenerator.genSuccessResult();
    }
}